/**
 * ReportGear(2011)
 */
package com.reportgear.designer.action.file;

import java.awt.Window;
import java.awt.event.ActionEvent;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import netscape.javascript.JSObject;

import com.reportgear.core.util.ImageUtils;
import com.reportgear.designer.action.ReportAction;
import com.reportgear.report.model.ReportModel;
import com.reportgear.report.setting.AppletSettings;
import com.reportgear.report.setting.ApplicationContext;

/**
 * 关闭操作
 * 
 * @version 1.0 2011-3-24
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since report 1.0
 */
public class CloseAction extends ReportAction {

	public CloseAction() {
		setName("关闭");
		setSmallIcon(ImageUtils.readIcon("/resources/images/file/close.png"));
	}

	public void actionPerformed(ActionEvent evt) {
		Object src = evt.getSource();
		if (src instanceof JComponent) {
			JComponent c = (JComponent) src;

			Window w = SwingUtilities.getWindowAncestor(c);

			if (ApplicationContext.INSTANCE.isApplet()) {
				w.dispose();
			} else {
				if (w instanceof JFrame) {
					System.exit(0);
				}
			}
		}
	}
}
